<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('新增医生信息')"/>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-serviceinfo-add">
        <div class="form-group">
            <label class="col-sm-3 control-label">头像：</label>
            <div class="col-sm-8">
                <img src="" style="width: 80px;height: 100px;display: none" id="logoImg">
                <input type="file" class="" id="logo" accept="image/*" onchange="uploadFile()"/>
                <input type="hidden" name="logo" id="logoVal" value="">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">科室：</label>
            <div class="col-sm-8">
                <select id="registerId" name="registerId" class="form-control">
                    <option th:each="register : ${registerinfoList}" th:text="${register['name']}"
                            th:value="${register['id']}"></option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">姓名：</label>
            <div class="col-sm-8">
                <select id="userId" name="userId" class="form-control">
                    <option th:each="user : ${userList}" th:text="${user['userName']}"
                            th:value="${user['userId']}"></option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">职称：</label>
            <div class="col-sm-8">
                <select name="typeInfo" class="form-control m-b" th:with="type=${@dict.getType('doc_professional')}">
                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                </select>
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-3 control-label">所在地区：</label>
            <div class="col-sm-8">
                <select name="areaName" class="form-control m-b">
                    <option th:each="area : ${areainfosList}" th:text="${area['areaName']}"
                            th:value="${area['areaName']}" th:attr="data-area-id=${area['areaId']}"></option>
                </select>
            </div>

            <div class="form-group">
                <label class="col-sm-3 control-label">所在医院：</label>
                <div class="col-sm-8">
                    <select id="hospitalId" name="hospitalId" class="form-control m-b">
                        <option th:each="hospital : ${HospitalinfoList}" th:text="${hospital['hospitalName']}"
                                th:value="${hospital['hospitalId']}"></option>
                    </select>
                </div>
            </div>

            <!--            <div class="form-group">-->
            <!--                <label class="col-sm-3 control-label">所在地区：</label>-->
            <!--                <div class="col-sm-8">-->
            <!--                    <select id="areaName" name="areaName" class="form-control">-->
            <!--                        <option th:each="area : ${areainfosList}" th:text="${area['areaName']}" th:value="${area['areaName']}"></option>-->
            <!--                    </select>-->
            <!--                </div>-->
            <!--            </div>-->

            <div class="form-group">
                <label class="col-sm-3 control-label">医生简介：</label>
                <div class="col-sm-8">
                    <textarea name="introduce" class="form-control"></textarea>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">挂号价格：</label>
                <div class="col-sm-8">
                    <input name="price" class="form-control" type="text">
                </div>

            </div>
    </form>
</div>
<th:block th:include="include :: footer"/>
<script type="text/javascript">
    var prefix = ctx + "register/serviceinfo"
    $("#form-serviceinfo-add").validate({
        focusCleanup: true
    });

    function uploadFile() {
        var formData = new FormData();
        if ($('#logo')[0].files[0] == null) {
            return false;
        }
        formData.append('file', $('#logo')[0].files[0]);
        var flag = true;
        $.ajax({
            url: ctx + "common/upload",
            type: 'post',
            cache: false,
            data: formData,
            processData: false,
            contentType: false,
            async: false,
            dataType: "json",
            success: function (result) {
                if (result.code == web_status.SUCCESS) {
                    var data = result.fileName;
                    $("#logoVal").val(data);
                    $("#logoImg").show();
                    $("#logoImg").attr("src", data);
                } else {
                    $.modal.alertError(result.msg);
                }
            },
            error: function (error) {
                $.modal.alertWarning("图片上传失败。");
            }
        });
        return flag;
    }


    function submitHandler() {
        if ($.validate.form()) {
            var data = $('#form-serviceinfo-add').serializeArray();
            // 获取所选选项的值和相关hospitalId
            // var hospitalSelect = $('select[name="hospital"]');
            // var selectedOption = hospitalSelect.find('option:selected');
            // var selectedValue = selectedOption.val();
            // var selectedHospitalId = selectedOption.data('hospital-id');

            var hospitalSelect1 = $('select[name="areaName"]');
            var selectedOption1 = hospitalSelect1.find('option:selected');
            var selectedValue1 = selectedOption1.val();
            var selectedHospitalId1 = selectedOption1.data('area-id');
            // alert(selectedHospitalId)
            // alert(selectedHospitalId1)
            // data.push({"name": "hospitalId", "value": selectedHospitalId});
            data.push({"name": "areaId", "value": selectedHospitalId1});
            $.operate.save(prefix + "/add", data);
        }
    }
</script>
</body>
</html>
